﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Net;

namespace HelloService
{
    /// <summary>
    /// Utility class to return a conection to WCF services in Worker roles
    /// </summary>
    public class HelloProxy
    {
     
        /// <summary>
        /// Return the URL string to connect to WCF service
        /// </summary>
        /// <param name="Ip"></param>
        /// <returns></returns>
        public static string GetUrlFormat(IPEndPoint Ip)
        {
            return string.Format("net.tcp://{0}/HellloService", Ip);
        }

        /// <summary>
        /// Return a instance of WCF service
        /// </summary>
        /// <param name="Url"></param>
        /// <returns></returns>
        public IHellloService GetAProxy(string Url)
        {
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
            EndpointAddress endpointAddress = new EndpointAddress(Url);

            return new ChannelFactory<IHellloService>
                (binding, endpointAddress).CreateChannel();
        }
 
    }
}
